package  
{
  import com.bit101.components.Label;
  import com.bit101.components.Style;
  import flash.display.Sprite;
	/**
   * ...
   * @author ivan
   */
  public class LetterView extends Sprite
  {
    
    public function LetterView(letters:Vector.<String>) 
    {
      for (var i:int = 0; i < letters.length; i++)
      {        
        var l:String = letters[i];
        Style.fontSize = 12;
        var pb:Label = new Label(this, 40 + 35 * i, 10, l);
        pb.width  = 30;
        pb.height = 30;
        letterButtons.push(pb);
      }
    }
    
    public function update(text:String, availableLetters:Vector.<String>):void
    {
      for (i = 0; j < letterButtons.length; j++)
        letterButtons[j].enabled = true;
          
      for (var i:int = 0; i < text.length; i++)
      {
        var t:String = text.charAt(i);
        for (var j:int = 0; j < letterButtons.length; j++)
        {
          var l:Label = letterButtons[j];
          if (l.text == t && l.enabled)
          {
            l.enabled = false;
            for (var k:int = 0; k < availableLetters.length; k++)
            {
              if (availableLetters[k] == t)
              {
                availableLetters.splice(k, 1);
                break;
              }
            }
            break;
          }
        }
      }
    }
    
    private var letterButtons:Vector.<Label> = new Vector.<Label>();
  }

}